library(tidyverse)
library(maps)
library(mapdata)
library(lubridate)
library(viridis)
library(wesanderson)
library(plotly)
library(ggplot2)
library(gganimate)
library(transformr)
library(gifski)

Mapping data to shapes

Interactive graph

Graphs with animation

Comparing confirmed cases and deaths between countries

# getting the time series data for confirmed cases

time_series_confirmed <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")) %>% rename(Province_State = "Province/State", Country_Region = "Country/Region")  %>% pivot_longer(-c(Province_State, Country_Region, Lat, Long), names_to = "Date", values_to = "Confirmed")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   `Province/State` = col_character(),
##   `Country/Region` = col_character()
## )
## See spec(...) for full column specifications.
# getting the time series data for deaths

time_series_deaths_long <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")) %>% rename(Province_State = "Province/State", Country_Region = "Country/Region")  %>% pivot_longer(-c(Province_State, Country_Region, Lat, Long), names_to = "Date", values_to = "Deaths")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   `Province/State` = col_character(),
##   `Country/Region` = col_character()
## )
## See spec(...) for full column specifications.
# create keys

time_series_confirmed <- time_series_confirmed %>% unite(Key, Province_State, Country_Region, Date, sep = ".", remove = FALSE)

time_series_deaths_long <- time_series_deaths_long %>% unite(Key, Province_State, Country_Region, Date, sep = ".") %>% select(Key, Deaths)

# join tables

time_series_long_joined <- full_join(time_series_confirmed, time_series_deaths_long, by = c("Key"))

time_series_long_joined <- time_series_long_joined %>% select(-Key)

# reformat the data

time_series_long_joined$Date <- mdy(time_series_long_joined$Date)

# create report table with counts

time_series_long_joined_counts <- time_series_long_joined %>% pivot_longer(-c(Province_State, Country_Region, Lat, Long, Date), names_to = "Report_Type", values_to = "Counts")

# generating the animation

data_time <- time_series_long_joined_counts %>% group_by(Country_Region,Date) %>% filter (Country_Region %in% c("Korea, South", "Japan", "India","Spain","Italy","US"))

p <- ggplot(data_time, aes(x = Date, y = log2(Counts), fill = Report_Type, color = Report_Type)) + geom_point() + geom_line() + ggtitle("COVID-19 confirmed cases and associated Deaths") + geom_point(aes(group = seq_along(Date))) + transition_reveal(Date) + facet_wrap(~Country_Region, ncol=2, scales="free_y")

animate(p,renderer = gifski_renderer(), end_pause = 15)